var parallel = require('../../utils/parallel').default;
var app = getApp();

Page({
  data: {
    name: '',
    userLogo: '../../image/uicon.jpg',
    logoUploaded:false,
    detail: {}
  },
  onLoad: function (options) {
   
  },
  /**
  * 生命周期函数--监听页面初次渲染完成
  */
  onReady: function () {
    var user = wx.getStorageSync("user");
    if (user) {
      this.setData({
        userLogo: user.userLogo,
        name: user.name
      })
    }

    wx.navigateTo({
      url: '../card1/card1?code=18359219330'
    })
  },

  uploadIcon: function (a) {
    var that = this;
    wx.chooseImage({
      count: 1,
      success: function (res) {
        console.log("文件选择：%o", res);
        if (res.tempFilePaths) {
          that.setData({
            userLogo: res.tempFilePaths[0]
          })
          console.log("预览本地图片");
          wx.uploadFile({
            url: 'https://wechat.neiyibaba.cn/common/file/upload/image',
            filePath: res.tempFilePaths[0],
            name: 'file',
            formData: {
              'token': wx.getStorageSync("token")
            },
            success: function (res) {
              var data = JSON.parse(res.data);
              that.setData({
                userLogo: data.url.indexOf(";jsessionid") != -1 ? data.url.substring(0, data.url.indexOf(";jsessionid")) : data.url,
                logoUploaded:true
              })

              console.log("预览上传后的图片");
            }
          })


        } else {
          wx.showToast({
            title: '未选择任何图片',
          })
        }
      },
    })
  },
  bindInputName: function (e) {
    this.setData({
      name: e.detail.value
    })
  },

  binSubmit: function () {
    var that = this;
    if (that.data.name != "" && that.data.name != null && that.data.name != undefined && that.data.name.replace(/ /g, "") != "" && that.data.logoUploaded==true) {
      var user = {
        userLogo: that.data.userLogo,
        name: that.data.name
      }
      wx.setStorageSync("user",user);
      wx.showLoading({
        title: '正在保存数据...'
      })

     setTimeout(function(){
       wx.hideLoading()
       wx.navigateTo({
         url: '../info-fill/info'
       })
     },1500);
    }else{
      wx.showModal({
        title: '提示',
        content: '请正确填写姓名并上传个人照片' + that.data.logoUploaded,
      })
    }
  }
})